package org.dormi.learn.primitive;

import org.dormi.learn.utils.Assert;

import java.util.Objects;

/**
 * 地址节点
 *
 * @author : dormi330
 * @version : 1.0
 */
public class AddressNode extends _Primitive_ implements Comparable<AddressNode> {

    // 如 江苏省, 门牌号200
    private final String name;

    // 如 10010, 200
    private final String code;

    // 如 省, 房间号
    private final String type;

    // 如 1, 7
    private final int level;

    /* === constructor === */
    /* === constructor === */
    /* === constructor === */

    public AddressNode(String code, String name, String type, int level) {
        Assert.isNotNull(code, "不能为null: AddressNode.code");
        Assert.isNotNull(name, "不能为null: AddressNode.name");
        Assert.isNotNull(type, "不能为null: AddressNode.type");

        this.name = name;
        this.code = code;
        this.type = type;
        this.level = level;
    }

    /**
     * level 小level 排序优先
     */
    public int compareTo(AddressNode o) {
        return this.level - o.level;
    }

    /* === hash/equals === */
    /* === hash/equals === */
    /* === hash/equals === */

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof AddressNode)) return false;
        AddressNode that = (AddressNode) o;
        return Objects.equals(getCode(), that.getCode());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getCode());
    }

    /* === set/get === */
    /* === set/get === */
    /* === set/get === */

    public String getName() {
        return name;
    }

    public String getCode() {
        return code;
    }

    public String getType() {
        return type;
    }

    public int getLevel() {
        return level;
    }
}
